/** EasyWeb spa v3.1.4 date:2019-07-12 License By http://easyweb.vip */

layui.config({
    //自定义修改
    version: true,   // 更新组件缓存，设为true不缓存，也可以设一个固定值
    //自定义修改
    base: 'assets/module/'
}).extend({
    setter: 'setter',
    reqApi: 'reqApi',
    promiseReq: 'promiseReq',
    sysLoad: 'sysLoad/sysLoad',
    reqEnum: 'reqEnum',
    formSelects: 'formSelects/formSelects-v4',
    treetable: 'treetable-lay/treetable',
    dropdown: 'dropdown/dropdown',
    notice: 'notice/notice',
    step: 'step-lay/step',
    dtree: 'dtree/dtree',
    citypicker: 'city-picker/city-picker',
    tableSelect: 'tableSelect/tableSelect',
	iconPicker: 'iconPicker/iconPicker',
    //自定义修改
    Cropper: 'Cropper/Cropper',
    zTree: 'zTree/zTree',
    introJs: 'introJs/introJs',
    fileChoose: 'fileChoose/fileChoose',
    tagsInput: 'tagsInput/tagsInput',
    CKEDITOR: 'ckeditor/ckeditor',
    Split: 'Split/Split',
    cascader: 'cascader/cascader'
    //自定义修改
}).use(['setter', 'layer', 'element', 'index', 'admin', 'laytpl', 'reqApi', 'promiseReq'], function () {
    var $ = layui.jquery;
    //自定义修改
    var layer = layui.layer;
    //自定义修改
    var element = layui.element;
    var setter = layui.setter;
    var index = layui.index;
    var admin = layui.admin;
    var laytpl = layui.laytpl;
    var reqApi = layui.reqApi;
    var promiseReq = layui.promiseReq;

    // 版本号显示
    $("#version").html("Version " + layui.cache.version);

    // 检查是否登录
    if (!setter.getToken()) {
        return location.replace('./view/home/login.html');
    }

    // 获取用户信息
    var selectUserInfo = promiseReq.req({
        url: reqApi.admin.home.selectUserInfo
        , type: 'get'
        , success: function (res) {
            setter.putUser(res.data);
            $('#huName').text(res.data.name);
        }
    });

    // 加载侧边栏
    var menu = promiseReq.req({
        url: reqApi.admin.home.menu
        , type: 'get'
        , success: function (res) {
            laytpl(sideNav.innerHTML).render(res.data, function (html) {
                $('.layui-layout-admin .layui-side .layui-nav').html(html);
                element.render('nav');
            });
            index.regRouter(res.data);  // 注册路由
            index.loadHome({            // 加载主页
                url: '#/home/home',
                name: '<i class="layui-icon layui-icon-home"></i>'
            });
        }
    });

    // 移除loading动画
    Promise.all([selectUserInfo, menu]).finally(function () {
        admin.removeLoading();
    });

});
